<template>
  <div>
    <template>
      <el-table
        :data="tableData5"
        style="width: 100%">
        <el-table-column
          prop="cid"
          label="稿件id"
		  width="100px"
        >
        </el-table-column>
        <el-table-column
          prop="name"
          label="姓名"
		  width="100px"
         >
        </el-table-column>
        <el-table-column
          prop="academy"
          label="学院"
         >
        </el-table-column>
        <el-table-column
          prop="class"
          label="班级"
         >
        </el-table-column>
		<el-table-column
		  prop="msg"
		  label="留言"
		  width="240px"
		 >
		</el-table-column>
		<el-table-column
		  prop="datetime"
		  label="时间"
		  width="160px"
		 >
		</el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button
              size="mini"
              @click="handleEdit(scope.$index, scope.row)">审核</el-button>
          </template>
        </el-table-column>
      </el-table>
	  
	  <!-- :visible.sync="dialogVisible" -->
	  <el-dialog
	    title="稿件内容"
		:visible.sync="dialogVisible"
	  	top="20px"
	    width="70%"
	    >
	  	<div v-html="showContent"></div>
		<!-- 定义按钮 -->
		<span slot="footer" class="dialog-footer">
			<el-button type="primary" @click="method2()">精品稿件</el-button>
			<el-button type="success" @click="method1()">普通稿件</el-button>
			<el-button type="info" @click="method3()">不合格稿件</el-button>
			<el-button @click="dialogVisible = false;seeid = ''">取消</el-button>
		</span>
	  </el-dialog>
    </template>
	  <div class="block" style="margin-top: 10px;">
		<el-pagination
		  background
		  layout="prev, pager, next"
		  :page-size='8'
		  :total="total"
		  :current-page="currentPage"
		  @current-change="handleCurrentChange"
		  >
		</el-pagination>
	  </div>
  </div>
</template>

<script>
export default {
  name: 'filterTable',
  data () {
    return {
      tableData5: [{
		  'cid': 1,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 2,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 3,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 4,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 5,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 6,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 7,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      },{
		  'cid': 8,
		  'name': '张三',
		  'academy': '家里蹲学院',
		  'class': '18网络',
		  'msg': '匿名播出',
		  'datetime': '2019-05-12 00:00:00'
      }],
	  total: 60,
	  currentPage: 1,
	  dialogVisible: false,
	  showContent: '',
	  seeid: ''
    }
  },
  created() {
	  this.axios.get(this.server + '/unCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
		  if(res == '0') {
			  this.$message.error("获取数据失败！")
		  }else {
			  this.tableData5 = res.data.tableData
			  this.total = res.data.total
		  }
	  },res => {
		  this.$message.error("网络错误！")
	  })
  },
  methods: {
    handleEdit (index, row) {
		this.$message.info("正在获取，请稍后！")
		this.axios.get(this.server + '/unCon/getConById?id=' + row.cid + '&token=' + this.store.getters.token).then(res => {
		  if(res.data != '0') {
			  this.showContent = res.data
			  this.dialogVisible = true
			  this.seeid = row.cid
		  }else {
			  this.$message.error("获取稿件内容失败！")
			  this.seeid = ''
		  }
		},res => {
			this.$message.error("网络连接失败！")
			this.seeid = ''
		})
    },
	handleCurrentChange(val) {
		this.axios.get(this.server + '/unCon/getMsg?page=' + val + '&token=' + this.store.getters.token).then(res => {
		  if(res.data != '0') {
			  this.tableData5 = res.data.tableData;
			  this.currentPage = val;
		  }
		},res => {
			this.$message.error("网络连接失败！")
		})
	},
	method1() {
		if(this.seeid != '') {
			this.axios.get(this.server + '/unCon/updateStatus?id=' + this.seeid + '&status=1&token=' + this.store.getters.token).then(res => {
				if(res.data == '1') {
					this.$message.success("审核成功！")
					this.dialogVisible = false
					this.axios.get(this.server + '/unCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
							  if(res == '0') {
								  this.$message.error("获取数据失败！")
							  }else {
								  this.tableData5 = res.data.tableData
								  this.total = res.data.total
							  }
					},res => {
							  this.$message.error("网络错误！")
					})
				}else {
					this.$message.error("审核失败！")
				}
			},res => {
				this.$message.error("请检查网络！")
			})
		}else {
			this.$message.error("请先阅读稿件！")
		}
	},
	method2() {
		if(this.seeid != '') {
			this.axios.get(this.server + '/unCon/updateStatus?id=' + this.seeid + '&status=2&token=' + this.store.getters.token).then(res => {
				if(res.data == '1') {
					this.$message.success("审核成功！")
					this.dialogVisible = false
					this.axios.get(this.server + '/unCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
							  if(res == '0') {
								  this.$message.error("获取数据失败！")
							  }else {
								  this.tableData5 = res.data.tableData
								  this.total = res.data.total
							  }
					},res => {
							  this.$message.error("网络错误！")
					})
				}else {
					this.$message.error("审核失败！")
				}
			},res => {
				this.$message.error("请检查网络！")
			})
		}else {
			this.$message.error("请先阅读稿件！")
		}
	},
	method3() {
		if(this.seeid != '') {
			this.axios.get(this.server + '/unCon/updateStatus?id=' + this.seeid + '&status=-1&token=' + this.store.getters.token).then(res => {
				if(res.data == '1') {
					this.$message.success("审核成功！")
					this.dialogVisible = false
					this.axios.get(this.server + '/unCon/getMsg?page=1&token=' + this.store.getters.token).then(res => {
							  if(res == '0') {
								  this.$message.error("获取数据失败！")
							  }else {
								  this.tableData5 = res.data.tableData
								  this.total = res.data.total
							  }
					},res => {
							  this.$message.error("网络错误！")
					})
				}else {
					this.$message.error("审核失败！")
				}
			},res => {
				this.$message.error("请检查网络！")
			})
		}else {
			this.$message.error("请先阅读稿件！")
		}
	}
  }
}
</script>

<style scoped>

</style>
